package com.quanyan.assets.repository;

import com.quanyan.assets.emun.AssetsErrorEnum;
import com.quanyan.assets.emun.OpType;
import com.quanyan.assets.emun.StatusType;
import com.quanyan.assets.entity.TbUserEggsAccumulateHistory;
import com.quanyan.assets.entity.TbUserEggsAccumulateHistoryExample;
import com.quanyan.assets.entity.TbUserShellAccumulateHistory;
import com.quanyan.assets.entity.TbUserShellAccumulateHistoryExample;
import com.quanyan.assets.mapper.ETbUserShellAccumulateHistoryMapper;
import com.quanyan.assets.mapper.TbUserShellAccumulateHistoryMapper;
import com.quanyan.assets.request.ReqUnfreeze;
import com.quanyan.assets.request.ReqUserAccumulateModifyBatch;
import com.quanyan.common.exception.BizException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by wmb on 2016/6/24.
 */
@Repository
public class ShellAccumulateHistoryRepository {
    @Autowired
    private TbUserShellAccumulateHistoryMapper tbUserShellAccumulateHistoryMapper;
    @Autowired
    private ETbUserShellAccumulateHistoryMapper eTbUserShellAccumulateHistoryMapper;

    public void insertAccumulateHistory(TbUserShellAccumulateHistory tbUserShellAccumulateHistory) {
        eTbUserShellAccumulateHistoryMapper.insertAccumulateHistory(tbUserShellAccumulateHistory);
    }

    public int updateFreezeStatus(ReqUnfreeze reqUnfreeze) {
        return eTbUserShellAccumulateHistoryMapper.updateFreezeStatus(reqUnfreeze);
    }

    public TbUserShellAccumulateHistory selectFreeze(ReqUnfreeze reqUnfreeze) {
        TbUserShellAccumulateHistoryExample tbUserShellAccumulateHistoryExample=new TbUserShellAccumulateHistoryExample();
        tbUserShellAccumulateHistoryExample.createCriteria().andSystemCodeEqualTo(reqUnfreeze.getSystemCode())
                .andBusinessCodeEqualTo(reqUnfreeze.getBusinessCode()).andBusinessNoEqualTo(reqUnfreeze.getBusinessNo())
                .andOpTypeEqualTo(OpType.CONSUME.id.byteValue()).andStatusEqualTo(reqUnfreeze.getStatus());
        List<TbUserShellAccumulateHistory> tbUserShellAccumulateHistoryList=tbUserShellAccumulateHistoryMapper.selectByExample(tbUserShellAccumulateHistoryExample);
        if(tbUserShellAccumulateHistoryList.isEmpty()){
            return null;
        }else{
            return tbUserShellAccumulateHistoryList.get(0);
        }
    }
}
